select * from dbo.Spider_Pages
select * from dbo.Spider_Sites

create procedure dbo.InsertChannel
@Name nvarchar(500)
as

Insert into dbo.Spider_Sites([Name])
values (@Name)
Select SCOPE_IDENTITY()
Go
--
--Declare @int int
--select @int = exec InsertChannel 'dantri.com.vn'

create procedure dbo.UpdateChannel
@SiteID int,
@Name nvarchar(500)
as

Update dbo.Spider_Sites set  Name=@Name
Where SiteID = @SiteID

Go

alter procedure dbo.InsertPage
@SiteID int,
@Url nvarchar(500),
@Name nvarchar(500),
@wID varchar(50),
@SourceCategoryID int

as

Insert into dbo.Spider_Pages(SiteId, Name,wID, Url, SourceCategoryID, CreatedDate,Status)
values(@SiteID,@Name, @wID, @Url, @SourceCategoryID, getdate(), 1)

Declare @intPageID int
Select @intPageID = SCOPE_IDENTITY()
if(@intPageID >0)
	Begin
	  Update dbo.Spider_Categories set TotalUrls = TotalUrls + 1
		 where OriginalCategoryID = @SourceCategoryID
	End
Select SCOPE_IDENTITY()
GO


create procedure dbo.InsertCategory
@SiteID int,
@Name nvarchar(500)
as

Insert into dbo.Spider_Categories(SiteID, Name)
values (@SiteID, @Name)
Select SCOPE_IDENTITY()

GO


create procedure dbo.UpdateCategory
@CateID int,
@Name nvarchar(500)
as

Update dbo.Spider_Categories set Name=@Name
where OriginalCategoryID = @CateID

GO
